classdef PacketLoser
    %PACKETLOSER Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
    end
    
    methods(Static)
        function ret = should_lose()
            ret = false;
            loss_rate_precentage = ParamsSingleton.instance().link_loss_rate_in_precentage();
            ret = ((rand()*100) < loss_rate_precentage);
        end
        
        function lose_packets(multi_packet)
            if PacketLoser.should_lose()
                loss_rate_ratio = (ParamsSingleton.instance().link_loss_rate_in_precentage()/100);
                num_of_packets = multi_packet.num_of_packets;
                num_of_packets_lost = max(1,floor(num_of_packets*loss_rate_ratio));
                multi_packet.packet_id_range_min = multi_packet.packet_id_range_min+num_of_packets_lost;
                fprintf('packet id %d lost %d packets\n',multi_packet.id,num_of_packets_lost);
            end
        end
    end
    
end

